package work.flow.demo.api;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.state.State;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisPool;
import work.flow.demo.entity.repository.BranchBean;
import work.flow.demo.entity.test01.LightEvent;
import work.flow.demo.entity.test01.LightState;
import work.flow.demo.mapper.branch.BranchMapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class Test02 {

    private static final Logger logger = LoggerFactory.getLogger(Test02.class);

    @Qualifier("MainSqlSessionFactory")
    private final SqlSessionFactory sqlSessionFactory;

    public Test02(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    @GetMapping("/201")
    public String get01(@RequestParam Map<String, String> params) {
        try (SqlSession session = sqlSessionFactory.openSession(true)) {
            HashMap<String, String> params1 = new HashMap<>();
            BranchMapper mapper = session.getMapper(BranchMapper.class);
            BranchBean bean = mapper.test01();
            String data = bean.data;
            return data;
        } catch (Exception e) {
            String message = e.getMessage();
            return "系统错误了：" + message;
        }
    }


}
